import { _decorator, Component, Label, Node, Script } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Monster')
export class Monster extends Component {
    // 怪物名称
    private monster_name: string = '';
    // 怪物ID
    private monster_id: string = '';
    // 怪物类型
    private monster_type: string = '';
    // 怪物等级
    private monster_level: number = 0;
    // 怪物血量
    private monster_hp: number = 100;
    // 怪物攻击力
    private monster_attack: number = 10;
    // 怪物防御力
    private monster_defense: number = 5;
    // 怪物描述
    private monster_description: string = '';
    // 跟玩家之间的关系,初始为0,,上限100,下限-100
    private relationship_with_player: number = 0;
    // 当前所在场景
    private current_scene: string = '';
    // 饥饿度,上限100,下限-100,小于50,小于0时怪物攻击伤害增加4%,每秒掉血2%
    private hunger: number = 50;
    // 睡眠度,上限100,为0时怪物进入睡眠状态
    private sleepiness: number = 50;
    // 怪物当前行动['发呆','闲逛','觅食','睡眠','努力变强']
    private current_action: string = '发呆';
    // 怪物身上的BUFF
    buffItems: any = [];
    // 怪物身上的DEBUFF
    deBuffItems: any = [];

    // 攻击方法
    attack(target: Monster) {
        // 检查攻击者的状态
        if (this.sleepiness <= 0) {
            console.log(`${this.monster_name} 正在睡眠，无法攻击。`);
            return;
        }

        // 计算伤害
        let damage = this.monster_attack - target.monster_defense;
        if (damage < 0) {
            damage = 0;
        }

        // 处理饥饿状态的伤害加成
        if (this.hunger < 50) {
            damage *= 1.04;
        } else if (this.hunger < 0) {
            damage *= 1.04;
            this.monster_hp -= this.monster_hp * 0.02;
        }

        // 减少防御者的血量
        target.monster_hp -= damage;

        // 处理特殊效果
        // 例如暴击、闪避、吸血等

        // 更新状态
        this.hunger -= 10;
        this.sleepiness -= 5;

        console.log(`${this.monster_name} 攻击了 ${target.monster_name}，造成了 ${damage} 点伤害。`);
        console.log(`${target.monster_name} 的剩余血量为 ${target.monster_hp}。`);
    }
}


